//
//  LzwThreeDetailVC.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/7.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwThreeDetailVC.h"
#import "LzwThreeDetailCell.h"
#import "Block.h"
#import "LzwThreeWebVC.h"
#import "LzwbaseTableView.h"

@interface LzwThreeDetailVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) LzwbaseTableView *myThreeDetailTableView;

@end

@implementation LzwThreeDetailVC

-(void)dealloc{
    [_myThreeDetailTableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"给生活添加点创意";
    
    self.myThreeDetailTableView = [[LzwbaseTableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.myThreeDetailTableView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.myThreeDetailTableView];
    
    
    UIImage * LandRightBar = [UIImage imageNamed:@"return.png"];
    LandRightBar = [LandRightBar imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:LandRightBar style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction:)];
    
    
    
    
    self.myThreeDetailTableView.delegate = self;
    self.myThreeDetailTableView.dataSource = self;
    
    self.arrayThree = [NSMutableArray array];
    
    [self.myThreeDetailTableView registerClass:[LzwThreeDetailCell class] forCellReuseIdentifier:@"cell"];
    
    NSString *str = @"http://open3.bantangapp.com/topic/list?app_installtime=1451365479.933367&app_versions=5.1.1&channel_name=appStore&client_id=bt_app_ios&client_secret=9c1e6634ce1c5098e056628cd66a17a5&device_token=c02c60075e7bab110fbdf27e15de3cb61e97360c4ea3545fd8a5936e46c28ccb&ids=1824%2C1832%2C1776%2C1613%2C1595%2C1534%2C1467%2C1423%2C1471%2C1234%2C1407&oauth_token=a41d3848f43102aa7759c27ba2c0fe8f&os_versions=9.1&page=0&pagesize=20&screensize=640&track_device_info=iPhone5%2C3&track_deviceid=A80585E3-D6AD-4A53-BE1C-5963901C96E5&track_user_id=1746436&v=9";
    
    [Block creatingDataTask:str parameters:nil Cookie:nil User_Agent:nil successAFNBlock:^(id resuposeObject) {
       
        NSMutableDictionary *dic = [resuposeObject objectForKey:@"data"];
        NSMutableArray *arrayThr = [dic objectForKey:@"topic"];
        
        for (NSMutableDictionary *diction in arrayThr) {
            
            LzwThreeDeModle *modleThr = [[LzwThreeDeModle alloc]init];
            
            [modleThr setValuesForKeysWithDictionary:diction];
            
            [self.arrayThree addObject:modleThr];
            
        }
        [self.myThreeDetailTableView reloadData];
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.arrayThree.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LzwThreeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.modleThree = [self.arrayThree objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LzwThreeWebVC *threeWebVC = [[LzwThreeWebVC alloc]init];
    
    threeWebVC.modleThr = [self.arrayThree objectAtIndex:indexPath.row];
    
    [self.navigationController pushViewController:threeWebVC animated:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 260;
}

- (void)leftButtonAction:(UIBarButtonItem *)bar{
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
